home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Developers / Advanced i⁄o / arithm_modadh.h < prev    next >
Encoding:
Text File  |  1995-05-10  |  2.9 KB  |  87 lines  |  [TEXT/ALFA]

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /*
  3.  ************************************************************************
  4.  *
  5.  *                    Arithmetic Coding
  6.  *          Adaptive Histogram-based model for the source of data
  7.  *
  8.  * This is an extension over the basic Input_Data_Model for an adaptive
  9.  * model of the input source, which, however, uses the histogram to
  10.  * find out which symbols are expected to come out and how often. This
  11.  * is to get around the flaw of the simple AdaptiveModel, which wastes
  12.  * the probability space by assigning the frequency count 1 to a lot
  13.  * of symbols that might appear but never show up in the reality. 
  14.  * E.g., in coding the Laplacian pyramid of typical images, the
  15.  * node value of the pyramid lies in the interval [-255,255].
  16.  * The simple AdaptiveModel assigns all the possible symbols
  17.  * (511 symbols) the frequency count at least 1. Though, it turns out
  18.  * that there are only about 130 distinct values of the pyramid nodes.
  19.  * I.e. only 130/511 of the probability space is made use of.
  20.  * Except that modification, the functionality of the present model is 
  21.  * very similar to that of the AdaptiveModel.
  22.  *
  23.  * The program assumes the total no. of distinct input symbols
  24.  * (integers) is relatively small, so simple linear arrays can be used
  25.  * for storing and looking up the frequency tables. 
  26.  *
  27.  * $Id: arithm_modadh.h,v 2.0 1995/02/07 19:37:05 oleg Exp oleg $
  28.  *
  29.  ************************************************************************
  30.  */
  31.  
  32. #ifndef __GNUC__
  33. #pragma once
  34. #endif
  35.  
  36. #ifndef _arithm_modadh_h
  37. #define _arithm_modadh_h
  38.  
  39. #ifdef __GNUC__
  40. #pragma interface
  41. #endif
  42.  
  43. #include "arithm.h"
  44. #include "histogram.h"
  45.  
  46. class AdaptiveHistModel : public Input_Data_Model
  47. {
  48.   Symbol symbol_lwb;            // Region potential input symbols
  49.   Symbol symbol_upb;            // are expected in
  50.   int no_potential_symbols;        // which are expected to occur
  51.   int no_distinct_symbols;        // which have occurred
  52.  
  53.   Index  * symbol_to_index;    // Symbol-to-index conversion
  54.   Symbol * index_to_symbol;    // Conversion from symbol index to symbol value
  55.  
  56.   void initialize_model(const Histogram& histogram);
  57.   void initial_distribution(void);    // Assign initial pdf
  58.  
  59. public:
  60.                     // Construct a model for a given
  61.                     // histogram
  62.   AdaptiveHistModel(const Histogram& histogram);
  63.   AdaptiveHistModel(void);        // With parameters are assumed to
  64.                     // be read in
  65.   virtual ~AdaptiveHistModel(void);
  66.  
  67.                     // Write out/Read in the histogram
  68.                     // to/from the coded stream
  69.   void open(BitIn& file);
  70.   void open(BitOut& file);
  71.  
  72.                     // Update the model to account 
  73.                     // for a symbol
  74.   void update_model(const Index index);
  75.  
  76.                     // Scale the accumulated statistics
  77.                     // down in anticipation of a change
  78.   void scale_down_past(void);
  79.  
  80.                     // Return the index of a symbol
  81.   Index  get_index(const Symbol symbol) const;
  82.                     // and the symbol for an index
  83.   Symbol get_symbol(const Index index) const;
  84. };
  85.  
  86. #endif
  87.